#include "SegmentTree.h"

int main() 
{
	int N;
	std::cin >> N;
	std::vector<double> arr(N);
	for (int i = 0; i < N; ++i)
	{
		std::cin >> arr[i];
	}
	int M;
	std::cin >> M;
	std::vector<std::pair<int, int>> segments(M);
	for (int i = 0; i < M; ++i)
	{
		int a, b;
		std::cin >> a >> b;
		segments[i] = std::make_pair(a, b);
	}

	SegmentTree T(arr);
	std::vector<double> result = T.minimum(segments);

	for (int i = 0; i < M; ++i)
	{
		int a, b;
		std::cout << result[i] << " ";
	}

	return 0;
}